#ifndef COLUMNWIDGET_H
#define COLUMNWIDGET_H

#include <QWidget>
#include <QListWidgetItem>

#include "../collections/columncollection.h"

namespace Ui {
    class ColumnWidget;
}

class ColumnWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ColumnWidget(const ColumnCollection& columns_,QWidget *parent = 0);
    ~ColumnWidget();

    void clearColumnForm();

    QList<KeyPair<Column> > getOrderedColumns();

public slots:
    void addColumn(const Column &column, const QString &key);
    void updateColumn(const QString& oldKey, const Column& newColumn,
                         const QString& newKey);
    void removeColumn(const QString& key);
    void clearAll();

signals:
    void addColumnRequested(const Column& column, const QString& key);
    void updateColumnRequested(const QString& oldKey, const Column& newColumn,
                                 const QString& newKey);
    void removeColumnRequested(const QString& key);

protected:
    void changeEvent(QEvent *event);

private slots:
    void on_colList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
    void on_colAdd_clicked();
    void on_colUpdate_clicked();
    void on_colDelete_clicked();

private:
    Ui::ColumnWidget *ui;

    const ColumnCollection *columns; // (Variable) pointer to const ColumnCollection
    QHash<QString, QListWidgetItem*> keyIndex;
};

#endif // COLUMNWIDGET_H
